<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">从业人员</small>
      </a>
      <router-link to='/Employeesadd' class="adds">
        <i class="el-icon-plus"></i>
      </router-link>
    </header>
    <main>
      <div class="seachfrom">
        <div class="seachbox">
          <el-input placeholder="请输入内容" v-model="seachtext">
            <el-button slot="append" icon="search" @click="seach()"></el-button>
          </el-input>
        </div>
      </div>
      <div>
        <v-loadmore :top-method="loadTop" :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" :auto-fill="false" ref="loadmore">
          <ul class="datalist">
            <li v-for="(item,index) in listData" :key='item.unid' :dataindex='index'>
              <router-link :to='{name: "Employeesdetail",query:{unid: item.unid}}'>
                <div class="items-img">
                  <img src="../../assets/iconimg.png" />
                </div>
                <div class="items-text">
                  <p>{{item.name}}</p>
                  <p>{{item.workType}}</p>
                </div>
              </router-link>
            </li>
          </ul>
        </v-loadmore>
        <div class="none_data" v-show="nonedata">
          <img src="../../img/tip.png">
        </div>
      </div>
    </main>
  </div>

</template>

<script>
  import {
    Loadmore
  } from 'mint-ui';
  import {
    EnterprisePerson
  } from '../../api/api';
  export default {
    components: {
      'v-loadmore': Loadmore,
    },
    data() {
      return {
        nonedata:false,
        PageSize:8,
        CurrentPage: 1,
        CriteriaList: [],
        listData: [],
        seachtext: '',
        select: '',
        allLoaded: false,
        scrollMode: "auto"
      };
    },
    methods: {
      loadTop: function() { //组件提供的下拉触发方法  
        //下拉刷新
         if (this.CurrentPage >= 0) {
            this.CurrentPage = 1;
            this.listData = [];
            this.getData();
        } else {
          this.listData = [];
          this.getData();
        }
        this.$refs.loadmore.onTopLoaded(); // 固定方法，查询完要调用一次，用于重新定位  
      },
      loadBottom: function() {
        // 上拉加载  
        this.CurrentPage += 1;
        this.getData();
        this.$refs.loadmore.onBottomLoaded(); // 固定方法，查询完要调用一次，用于重新定位  
      },
      //搜索
      seach: function() {
        this.listData = [];
        this.CurrentPage=1;
        this.CriteriaList[0] = {
          Name: 'Name',
          Value: '%' + this.seachtext + '%',
          Operate: 'Like',
          DataType: null,
          EndSuffix: '',
          Suffix: null
        };
        this.getData();
      },
      //数据加载方法
      getData() {
        let CurrentPageNum= this.CurrentPage
        let varQueryData = {
          PageSize: this.PageSize,
          CurrentPage: this.CurrentPage,
          Query: {
              CriteriaList:[],
              SubQueryList:[]
          }
        }
        if(this.CriteriaList.length!==0){
          let SubQueryList= [{
                CriteriaList: this.CriteriaList,
                Relation: 'or'
              }]
          varQueryData.Query.SubQueryList=SubQueryList;
        }
        let options = {
          params: {
            UserUnid: JSON.parse(localStorage.getItem('auth')).UserUnid,
            QueryData: JSON.stringify(varQueryData),
            EnterpriseUnid:JSON.parse(localStorage.getItem('auth')).enterpriseUnid,
            EnterpriseName:JSON.parse(localStorage.getItem('auth')).enterpriseUnid,
          }
        }
        //调取接口
        EnterprisePerson(options).then((res) => {
          if (res.success === true) {
            this.user = res.data.user;
            this.listData = this.listData.concat(res.data);
            if (res.data.length > 0) {
              this.nonedata = false
            } else {
              if (CurrentPageNum == 1) {
                this.nonedata = true
              } else {
                this.nonedata = false
              }
            }
          }
        })
      }
    },
  
    //页面加载时候
    mounted() {
      this.getData();
    }
  
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style lang="scss" scoped>
.datalist li{
  overflow:hidden
}
.items-img{
    padding: 0;
    margin: 0;
    list-style: none;
    font-style: normal;
    text-decoration: none;
    border: none;
    color: #333;
    font-weight: 400;
    font-family: Microsoft Yahei;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    img{
          width: 2.7rem;
          height: 2.7rem;
          display: block;
          margin-right: .4rem;
    }
}
.items-text{
      -webkit-box-flex: 1;
    -ms-flex: auto;
    flex: auto;
}
.items-text p:first-child{
  font-size: 1rem;
  margin-bottom:0.2rem
}
.items-text p:last-child{
 color:#666
}

</style>
